import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import {Device} from "@ionic-native/device";
import {InfoProvider} from "../providers/InfoProvider";
import {HttpService} from "../providers/HttpService";

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
    rootPage: any;

    constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,
                private device: Device,
                private infoProvider: InfoProvider) {
        platform.ready().then(() => {
            // Okay, so the platform is ready and our plugins are available.
            // Here you can do any higher level native things you might need.
            statusBar.styleDefault();
            splashScreen.hide();
            statusBar.backgroundColorByHexString('#262e38');

            infoProvider.setDevice(this.device);
            infoProvider.syncUserInfo().then(res => {
                console.log('MyApp: ', res);
                if (res && res.type >= 0) {
                    HttpService.setAuthPrimary(res.token);
                    this.rootPage = 'TabsPage';
                } else {
                    this.rootPage = 'LoginPage';
                }
            });
        });
    }
}
